
package network.sslProxy;

import java.net.ServerSocket;
import java.net.Socket;
import java.util.Date;

import network.utils.ProxyConstants;

/**
 * Start SSL Proxy Server in local port which receive CONNECT Command.
 * 
 * @author http://arunava.in
 */
public class SSLProxyStarter extends Thread {
	public static int started = 0;
	public static void main(final String[] args) {
		new SSLProxyStarter().run();
	}

	public void run() {
		if (ProxyConstants.logLevel >= 1) {
			System.out.println(new Date()
					+ " SSLProxyStarter :: SSL Proxy started :: On "
					+ ProxyConstants.SSLProxyPort);
		}

		try {
			final ServerSocket sc = new ServerSocket(ProxyConstants.SSLProxyPort);
			while (true) {
				started = 1;
				final Socket cSocket = sc.accept();
				new SSLProxyHandler(cSocket).start();
				if (ProxyConstants.logLevel >= 2) {
					System.out.println(new Date()
							+ " SSLProxyStarter :: New client connected from  "
							+ cSocket);
				}
			}
		} catch (final Exception e) {
			started = 2;
			System.out.println(new Date() + "SSLProxyStarter :: Error " + e);
		}
	}
}